package com.battery.controller;


import com.battery.pojo.MerChant;
import com.battery.service.MerChantService;
import com.battery.util.result.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "商铺管理相关接口")
@RequestMapping("/merchant")
public class MerchantController {

    @Autowired
    private MerChantService merChantService;


    @PostMapping("/saveMerchant")
    @ApiOperation("添加商铺")
    public Result addMerchant(@RequestBody @ApiParam(name="商铺对象",value="传入json格式",required=true) MerChant merChant) {
        return merChantService.insert(merChant);
    }

    @GetMapping("/searchAllMerchant/{key}")
    @ApiOperation("根据key对商铺进行模糊查询商铺")
    public Result searchAllMerchant(@ApiParam(name="查询关键字" ,defaultValue = " ") String key) {
        return merChantService.findAllMerChantsByKey(key);
    }

    @GetMapping("/searchMerchantInfo/{id}")
    @ApiOperation("根据id查询商铺")
    public Result getUserById(@ApiParam(name="商铺id",required=true) int mer_id) {
        return merChantService.searchMerChatById(mer_id);
    }
    @PutMapping("/updateMerchant")
    @ApiOperation("根据id更新商铺")
    public Result updateUserById(@RequestBody @ApiParam(name="商铺对象",value="传入json格式",required=true) MerChant merChant) {
        return merChantService.update(merChant);
    }

    @DeleteMapping("/deleteMerchant/{id}")
    @ApiOperation("根据id删除商铺")
    public Result deleteUserById(@RequestBody @ApiParam(name="商铺id",required=true) int mer_id) {
        return merChantService.delete(mer_id);
    }
}